package com.springboot.demo.controller;

import com.springboot.demo.utils.ResponseResult;
import com.springboot.demo.utils.ResponseUtils;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;
import java.util.Set;

/**
 * @author wubc683
 * @desc
 * @date 2021-11-08 17:56
 */
//@RestController
//@Api("缓存清理")
//@Slf4j
//public class CacheController {
//    @Qualifier("redisCacheManager")
//    @Autowired
//    private CacheManager managerServer;
//    @Autowired
//    ResponseUtils responseUtils;
//
//    @DeleteMapping("/delete/cache")
//    public ResponseUtils clean() {
//        try {
//            Set<String> names = (Set<String>) managerServer.getCacheNames();
//            names.forEach(e -> {
//                Cache c = managerServer.getCache(e);
//                if (Objects.isNull(c)) {
//                    return;
//                }
//                c.clear();
//            });
//            return responseUtils.buildSuccessResponse("clean cache list:" + managerServer.getCacheNames());
//        } catch (Exception e) {
//            log.error(e.getMessage(), e);
//            return responseUtils.buildFailedResponse(ResponseResult.CACHE_CLEAN_ERROR, ",原因："+e.getMessage());
//        }
//    }
//}